<template>
  <hi-row
    isColumn
    :wrap="false"
    class="viewcontainer"
    v-if="dataset && subDataSet"
  >
    <hi-col flex="350px">
      <hi-form
        :dataSource="dataset"
        ref="detailForm"
        :model="dataset.curRecord"
        v-bind="form"
      ></hi-form>
    </hi-col>
    <hi-col flex="auto" :min-height="200">
      <hi-table
        ref="detailTable"
        :dataSource="subDataSet"
        v-bind="dataTable"
        :model="subDataSet.data"
      ></hi-table>
    </hi-col>
  </hi-row>
</template>

<script>
import { HiForm, DataSetContainer, HiNumber, HiTable } from "hi-ui";
import viewBase from "../../base";
import prescriptionListCfg from "./dataset/prescriptionList";
import detailCfg from "./dataset/detail";
export default {
  name: "prescriptionDetail",
  extends: viewBase,
  components: { HiForm, HiTable, HiNumber },

  data() {
    return {
      //数据集
      dataset: null,
      //数据集配置
      datasetCfg: prescriptionListCfg,
      //从表数据集
      subDataSet: null,
      //从表数据集配置
      subDatasetCfg: detailCfg,

      //数据桥梁
      dataBridge: new Map(),
      //数据表格
      dataTable: {
        // isEdit: true,
        // hasSelection: true,
        // hasRowNumber: true,

        columns: [
          {
            name: "prescription_id",
          },
          {
            name: "drug_code",
          },
          {
            name: "drug_in_store",
          },
          {
            name: "drug_name",
          },
          {
            name: "specifications",
          },
          {
            name: "each_times",
          },
          {
            name: "quantity",
          },
          {
            name: "frequency",
          },

          {
            name: "total_day",
          },
          {
            name: "drug_usage",
          },
          {
            name: "total_quantity",
          },
          {
            name: "unit",
          },
          {
            name: "opinion",
          },
        ],
      },
      //表单配置
      form: {
        columnsTotal: 2,
        items: [
          {
            name: "patient_name",
          },

          {
            name: "patient_sex",
          },
          {
            name: "patient_age",
          },
          {
            name: "patient_weight",
          },
          {
            name: "parient_phone",
          },
          {
            name: "history_of_present_illness",
          },
          {
            name: "past_history",
          },

          {
            name: "allergies",
          },
          {
            name: "opinion",
          },
          // {
          //   name: "prescription_type",
          // },
          // {
          //   name: "prescription_nature",
          // },
          {
            name: "money",
            props: {
              format: "￥0.00",
              precision: 2,
            },
          },
          {
            name: "take_drug",
            element: "el-tag",
            injection: "domProps.innerHTML",
            // style: {
            //   color: "blue",
            // },
            props: {
              type: "success",
              // effect: "",
              format: function (val) {
                return val == 1 ? "已取药" : "未取药";
              },
            },
            domProps: {
              innerHTML: "",
            },
          },
          {
            name: "payment_or_not",
            element: "el-tag",
            injection: "domProps.innerHTML",
            style: {
              color: "",
            },
            props: {
              type: "success",
              // effect: "plain",
              format: function (val) {
                return val == 1 ? "已付款" : "未付款";
              },
            },
            domProps: {
              innerHTML: "",
            },
          },

          {
            name: "doctor_name",
          },

          {
            name: "create_date",
          },
        ],
      },
    };
  },
  model: {
    prop: "value",
    event: "valuechange",
  },
  props: {
    value: {
      type: Object,
    },
  },

  computed: {},
  watch: {},
  methods: {},
  mounted() {
    var _this = this;
    //创建主数据集
    this.dataset = this.createDataSet(this.datasetCfg);
    this.dataset.on("dirtychange", (store, dirty) => {
      console.log("dataset" + dirty);
    });
    this.dataset.on("afterload", function (response, data, store) {
      debugger;
      _this.form.items.forEach((element) => {
        debugger;
        if (!data[0].take_drug && element.name == "take_drug") {
          element.props["type"] = "danger";
        }
        if (!data[0].payment_or_not && element.name == "payment_or_not") {
          element.props["type"] = "danger";
        }
        if (element.name == "patient_sex") {
          if (data[0].patient_sex == "1") {
            store.data[0].patient_sex = "男";
          } else if (data[0].patient_sex == "2") {
            store.data[0].patient_sex = "女";
          } else {
            store.data[0].patient_sex = "未知";
          }
        }
      });
    }),
      //创建从数据集
      (this.subDataSet = this.createDataSet(this.subDatasetCfg, this.dataset));

    //设置数据与组件的关系
    this.dataBridge.set(this.dataset, ["detailForm", "detailTable"]);
    this.flowConfig = { dataset: this.dataset };
    if (this.$route.query.id) {
      this.dataset.load({
        record_id: this.$route.query.id,
      });
    }
  },
};
</script>
<style rel="stylesheet/scss" lang="scss" scope>
</style>

